<!--
 * @Author: MrDotYan 2564217790@qq.com
 * @Date: 2024-09-14 15:43:48
 * @LastEditors: MrDotYan 2564217790@qq.com
 * @LastEditTime: 2024-09-23 11:49:06
 * @FilePath: /webServerAdmin/src/views/system/email/components/view.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <el-drawer v-model="visible">
    <div class="drawer-wrapper">
      <div class="mobile">
        <div style="box-sizing: border-box; padding: 0 10px">
          <div class="title">
            <span>{{ modelValue.title }}</span>
          </div>
          <div class="subject">
            <span>{{ modelValue.subject }}</span>
          </div>
          <div class="receiver">
            <span>邮件接收者</span>
            <el-link :href="`mailto:${modelValue.receiver}`">{{ modelValue.receiver }}</el-link>
          </div>
        </div>
        <el-divider style="margin: 10px 0"></el-divider>
        <div class="context">
          <el-scrollbar>
            <div v-html="modelValue.context"></div>
          </el-scrollbar>
        </div>
      </div>
    </div>
  </el-drawer>
</template>

<script lang="tsx" setup>
import { ref, reactive } from "vue";
import { fetchEmailInfo } from "@/api/modules/email";
import { EmailSchema } from "@/schema";

const visible = ref<boolean>(false);
const modelValue = reactive<EmailSchema>({
  receiver: "",
  title: "",
  subject: "",
  context: ""
});

defineExpose({
  open(row) {
    if (row.id) {
      fetchEmailInfo({ id: row.id }).then(r => {
        Object.assign(modelValue, r.data);
      });
      visible.value = true;
    }
  }
});
</script>

<style lang="scss" scoped>
.drawer-wrapper {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
}
.mobile {
  box-sizing: border-box;
  width: 365.4px;
  height: 730.8px;
  padding: 52px 28px;
  background: url("@/assets/images/iphone_x.png") no-repeat center center; /* 添加 no-repeat 和 center center */
  background-size: cover; /* 使背景图片适应盒子大小 */
  .title {
    font-size: 18px;
    color: #000000;
  }
  .subject {
    font-size: 14px;
    color: #666666;
  }
  .receiver {
    padding: 6px 0;
    color: #666666;
    text-align: right;
  }
  .context {
    box-sizing: border-box;
    width: 100%;
    height: calc(100% - 102.5px);
    padding: 0 10px;
    &:deep(img) {
      width: 100% !important;
    }
    &:deep(video) {
      width: 100% !important;
    }
  }
}
</style>
